package com.johnsoft.pph.gui;

import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.johnsoft.pph.Installer;

public class PPHGui extends Thread {
	
	private JFrame installerFrame;
	private IGui guiToDisplay;
	public static JBackground backgroundImage;
	
	public PPHGui() {
		Dimension size = new Dimension(500, 350);
		installerFrame = new JFrame("The Pre-PreHistoric Mod Installer");
		installerFrame.setResizable(false);
		installerFrame.setPreferredSize(size);
		installerFrame.setMinimumSize(size);
		installerFrame.setMaximumSize(size);
		installerFrame.addWindowListener(new GuiManager());
		backgroundImage = new JBackground();
		installerFrame.setContentPane(backgroundImage);
		start();
	}
	
	public void addText(String s)
	{
		addText(s, true);
	}
	
	public void addText(String s, boolean endline)
	{
		if(guiToDisplay instanceof GuiInstall)
		{
			((GuiInstall)guiToDisplay).console.setText(((GuiInstall)guiToDisplay).console.getText() + s);
			if(endline)
				((GuiInstall)guiToDisplay).console.setText(((GuiInstall)guiToDisplay).console.getText() + "\r\n");
		}
	}
	
	public void run()
	{
		installerFrame.repaint();
		try
		{
			Thread.sleep(100);
		}
		catch(Exception e)
		{
		}
	}
	
	public void setGUI(IGui gui)
	{
		if(guiToDisplay != null)
			installerFrame = guiToDisplay.cleanFrame(installerFrame);
		guiToDisplay = gui;
		installerFrame = guiToDisplay.registerFrame(installerFrame);
	}

}
